<tagLib name="lbase"/>
<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="utf-8">
        <title>微信公众平台营销管理系统</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">
    <include file='Public:header' />
    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="__ROOT__/public/js/html5shiv.js"></script>
    <![endif]-->
</head>

<body>
    <!--nav-->
<include file='Public:nav' />


<div class="container">
    <div class="page-header"><h4>用户编辑</h4></div>
    <div class="row">
        <div class="span12">
            <div class="pull-left">
                <a href="{$pre_url}" class="btn btn-primary">返回</a>&nbsp;&nbsp;
            </div>
        </div>
    </div>
    <div class="row">
        <div class="span12" style="margin-top:10px;">
            <form class="form-horizontal" method="post">
                <fieldset>
                    <div id="legend" class="">
                        <legend class=""></legend>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="input01">用户名</label>
                        <div class="controls">
                            <input type="text" placeholder="" value="{$info.user_name}" name="user_name" class="input-xlarge">
                            <p class="help-block">登录用户名，英文字母</p>
                        </div>
                    </div>

                    <div class="control-group">
                        <label class="control-label" for="input01">昵称</label>
                        <div class="controls">
                            <input type="text" placeholder="" value="{$info.title}" name="title" class="input-xlarge">
                            <p class="help-block">用户昵称，方便后期管理</p>
                        </div>
                    </div><div class="control-group">
                        <label class="control-label" for="input01">修改登录密码</label>
                        <div class="controls">
                            <input type="password" placeholder="" name="user_pwd" class="input-xlarge">
                            <p class="help-block">6位以上字母+数字,如不需修改密码请保持为空</p>
                        </div>
                    </div>

                    <div class="control-group">
                        <label class="control-label" for="input01">确认密码</label>
                        <div class="controls">
                            <input type="password" placeholder="" name="user_pwd_confirm" class="input-xlarge">
                            <p class="help-block">请确认登录密码</p>
                        </div>
                    </div>

                    <div class="control-group">
                        <label class="control-label">状态</label>
                        <div class="controls">
                            <label class="radio inline">
                                <input type="radio" name="status" value="1"<php>if($info['status']==1) echo ' checked="checked"';</php>>
                                启用
                            </label>
                            <label class="radio inline">
                                <input type="radio" value="0" name="status"<php>if($info['status']==0) echo ' checked="checked"';</php>>
                                禁用
                            </label>
                        </div>
                    </div>

                    <div class="control-group">
                        <label class="control-label">备注</label>
                        <div class="controls">
                            <div class="textarea">
                                <textarea type="" class="" name="remark">{$info.remark}</textarea>
                            </div>
                        </div>
                    </div>
                    <div id='pop'></div>

                    <div class="form-actions">
                        <input type="hidden" name="id" value="{$info.id}">
                        <button type="button" class="btn btn-primary" id='save'>保 存</button>&nbsp;&nbsp;
                        <a class="btn" href="{$pre_url}">返 回</a>
                    </div>

                </fieldset>
            </form>
        </div>
    </div>
</div>
</div>

<include file='Public:footer' />
<script type="text/javascript">
    $(function() {
        var save_button = $('#save');
        save_button.click(function() {
            if (check_fields()) {
                ajax_action();
            }
        });

        function ajax_action() {
            var data = $('form').serialize();
            save_button.attr('disabled', 'disabled');
            $.ajax({
                type: "POST",
                url: app_url + "/" + module_name + "/update",
                data: data,
                dataType: 'json',
                cache: false,
                success: function(data) {
                    success(data);
                },
                error: function() {
                    error();
                }
            });
        }

        function check_fields() {
            if ($("[name=user_name]").val() == '') {
                alert('请填写用户名!');
                $("[name=user_name]").focus();
                return false;
            }
            if ($('[name=user_pwd]').val() != $('[name=user_pwd_confirm]').val()) {
                alert('您两次填写的登陆密码不一致,请检查后重新输入!');
                $('[name=user_pwd]').val('');
                $('[name=user_pwd_confirm]').val('');
                $("[name=user_pwd]").focus();
                return false;
            }
            return true;
        }

        $('#pop').ajaxStart(function() {
            $('#pop').html('<div class="alert alert-info"><button type="button" class="close" data-dismiss="alert">×</button>数据请求中，请稍候...</div>')
                    .fadeIn("slow");
        });

        function success(data) {
            switch (data.data) {
                case 1:
                    $('#pop').html('<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button>信息修改成功！</div>')
                            .fadeIn("slow");
                    save_button.removeAttr('disabled');
                    break;
                case 2:
                    $('#pop').html('<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button>两次密码输入的不一致,请重新输入!</div>')
                            .fadeIn("slow")
                            .fadeOut(5000);
                    save_button.removeAttr('disabled');
                    break;
                default:
                    $('#pop').html('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>信息修改失败或者无需要修改！</div>')
                            .fadeIn("slow");
                    save_button.removeAttr('disabled');
            }
        }


        function error() {
            $('#pop').html('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>远程服务器请求失败！</div>')
                    .fadeIn("slow")
                    .fadeOut(5000);
        }
    });
</script>
</body>
</html>
